package com.nail.zhaogr.front.action;

import java.util.List;

import cn.org.rapid_framework.page.Page;

import com.nail.zhaogr.model.Category;
import com.nail.zhaogr.model.City;
import com.nail.zhaogr.model.PublishInfo;
import com.nail.zhaogr.service.CategoryManager;
import com.nail.zhaogr.service.CityManager;
import com.nail.zhaogr.service.PublishInfoManager;
import com.nail.zhaogr.vo.query.PublishInfoQuery;
@SuppressWarnings({ "unchecked", "serial" })
public class IndexAction  extends BaseAction{
	//默认多列排序,example: username desc,createTime asc
	protected static final String DEFAULT_SORT_COLUMNS = "updateTime desc"; 
	
	//forward paths
	protected static final String LIST_JSP= "/index.jsp";
	protected static final String MAIN_JSP= "/main.jsp";
	
	private PublishInfoManager publishInfoManager;
	
	private CityManager cityManager;
	private CategoryManager categoryManager;
	
	private PublishInfo publishInfo;
	java.lang.Long id = null;
	
	private List<City> cityList;
	private List<Category> categoryList;
	
	private List<PublishInfo> publishInfoList;
	

	public void prepare() throws Exception {
		this.getPageUrl();
		if (isNullOrEmptyString(id)) {
			publishInfo = new PublishInfo();
		} else {
			publishInfo = (PublishInfo)publishInfoManager.getById(id);
		}
	}
	
	/** 增加setXXXX()方法,spring就可以通过autowire自动设置对象属性 */
	public void setPublishInfoManager(PublishInfoManager manager) {
		this.publishInfoManager = manager;
	}	
	
	public Object getModel() {
		return publishInfo;
	}
	
	public void setPublishInfoId(java.lang.Long val) {
		this.id = val;
	}
	
	/** 执行搜索 */

	public String index() { 
		PublishInfoQuery query = newQuery(PublishInfoQuery.class,DEFAULT_SORT_COLUMNS);
		this.setTitle(getCurrentCity().getName()+"找工人_");
		query.setStatus(1);
		query.setType(1);
		query.setParentCityId(getCurrentCity().getCityId());
		//query.setCityTwo(getCurrentCity().getName());
		query.setParentCityId(getCurrentCity().getCityId());
		Page page = publishInfoManager.findPage(query);
		limitLength(page);
		savePage(page,query);
		return MAIN_JSP;
	}
	
	public String loginSuccess() {
		//PageRequest<Map> pageRequest = newPageRequest(DEFAULT_SORT_COLUMNS);
		//pageRequest.getFilters().put("key",value);     //add custom filter
		//pageRequest.getFilters().put("status",1);
		//page = publishInfoManager.findByPageRequest(pageRequest);
		//savePage(page,pageRequest);
		return "/main.jsp";
	}

	public List<City> getCityList() {
		return cityList;
	}

	public void setCityList(List<City> cityList) {
		this.cityList = cityList;
	}

	public List<Category> getCategoryList() {
		return categoryList;
	}

	public void setCategoryList(List<Category> categoryList) {
		this.categoryList = categoryList;
	}


	public void setCityManager(CityManager cityManager) {
		this.cityManager = cityManager;
	}

	public void setCategoryManager(CategoryManager categoryManager) {
		this.categoryManager = categoryManager;
	}

	public List<PublishInfo> getPublishInfoList() {
		return publishInfoList;
	}

	public void setPublishInfoList(List<PublishInfo> publishInfoList) {
		this.publishInfoList = publishInfoList;
	}
}
